package com.taotao.tools.codec.password;


import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.mindrot.jbcrypt.BCrypt;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class PasswordCodec {


    /**
     * 加密密码
     *
     * @param password
     * @param saltLen
     * @return
     */
    public static String encodePassword(String password, int saltLen) {
        return BCrypt.hashpw(password, BCrypt.gensalt(saltLen));
    }


    /**
     * 检查密码与加密后的密码是否相符
     *
     * @param target
     * @param encodedPassword
     * @return
     */
    public static boolean checkPassword(String target, String encodedPassword) {
        return BCrypt.checkpw(target, encodedPassword);
    }


}
